#

| Chapter 18 |

# 18. Linking, Renaming, and Copying Files

Contents:
What's So Complicated About Copying Files?
What's Really in a Directory
Files with Two or More Names
More About Links
Creating and Removing Links
Stale Symbolic Links
Linking Directories
Showing the Actual Filenames for Symbolic Links
Renaming, Copying, or Comparing a Set of Files
There's More than One Way to Do It
Renaming Files with ren
Renaming a List of Files Interactively
One More Way to Do It
Relinking Multiple Symbolic Links
Copying Directory Trees with cp -r
Copying Directory Trees with (tar | tar)

## 18.1 What's So Complicated About Copying Files?

It hardly seems that there should be enough material to fill an entire chapter with information about linking, moving, and copying files. There are several things that make the topic more complex (and more interesting) than you might expect:

- In addition to moving and copying files, UNIX systems also allow you to link them - to have two filenames, perhaps in different directories or even on different filesystems, that point to the same file. We talk about why you'd want to do that (article 18.3), the difference between "hard" and "soft" links (article 18.4), how to create links (article 18.5), and various issues that can come up when using links (articles 18.6, 18.7, and 18.8).

- It is non-trivial to rename a group of files all at once, but as usual, UNIX provides many ways to circumvent the tedium of renaming files one by one. We show you many different ways to do this, exploring the variety in the UNIX toolbox along the way.

- In a hierarchical filesystem, you're sometimes faced with the problem of moving not only files but entire directory hierarchies from one place to another. Articles 18.15 and 18.16 show you two ways to do that. Of course, this discussion starts to get into the territory covered by the next two chapters. Chapter 19 covers "archives"-large files that include many other files and directories, with instructions for recreating copies of the original files and directories. Chapter 20 covers backups - which are typically archive files copied to tape.

- TOR

17.25 Keeping find From Searching Networked Filesystems |  | 18.2 What's Really in a Directory